﻿// Open Source: MIT License (http://www.opensource.org/licenses/mit-license.php)
// Project: YoProgramo.NET (http://code.google.com/p/yoprogramo/)
// Autor: Fabian Figueredo (info@fabianfigueredo.com.ar)
// Blog: blog.yoprogramo.net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Validator;
using YoProgramo.Domain.Core.Interfaces;

namespace YoProgramo.Domain.Core.Entities
{
    public class User : EntityBase<long>, IUser, IHasAssignedId<long> {
        public virtual void SetAssignedIdTo(long assignedId)
        {
            throw new NotImplementedException();
        }

        public override int GetHashCode()
        {
            return (GetType().FullName + "|" +
                    UserName + "|" +
                    Email).GetHashCode();
        }

        private string _username;

        [Length(4, 15, Message = "El campo UserName debe tener entre 4 y 15 caracteres.")]
        [NotNullNotEmpty(Message = "El campo UserName no puede ser nulo.")]
        public virtual string UserName
        {
            get { return _username; }
            set { _username = value; }
        }

        private string _password;
        [Length(4, 100, Message = "El campo Password debe tener entre 4 y 100 caracteres.")]
        [NotNullNotEmpty(Message = "El campo Password no puede ser nulo.")]
        public virtual string Password
        {
            get { return _password; }
            set { _password = value; }
        }

        private string _email;

        [Length(5, 28, Message = "El campo Email debe tener entre 5 y 28 caracteres.")]
        [Email(Message = "Formato incorrecto de Email")]
        [NotNullNotEmpty]
        public virtual string Email
        {
            get { return _email; }
            set { _email = value; }
        }


        private bool _isactive;
        public virtual bool IsActive
        {
            get { return _isactive; }
            set { _isactive = value; }
        }

        private bool _islockedout;
        public virtual bool IsLockedOut
        {
            get { return _islockedout; }
            set { _islockedout = value; }
        }


        private Roles _role;
        public virtual Roles Role
        {
            get { return _role; }
            set { _role = value; }
        }


        public DateTime _registeredAt;
        public DateTime RegisteredAt {
            get {
                return _registeredAt;
            }
            set {
                _registeredAt = value;
            }
        }



        private DateTime _lastactivityat;
        public virtual DateTime LastActivityAt
        {
            get { return _lastactivityat; }
            set { _lastactivityat = value; }
        }

        public long Id {
            get { return base.Id; }
            set { base.Id = value; }
        }

        private long? _reputacion;
        public long? Reputation {
            get {
                return _reputacion;
            }
            set {
                _reputacion = value;
            }
        }


        #region IUser Members


        private IList<IStory> _favoritesStories;
        public IList<IStory> FavoritesStories {
            get {
                return _favoritesStories;
            }
            set {
                _favoritesStories = value;
            }
        }

        private string _pais;
        public string Pais {
            get {
                return _pais;
            }
            set {
                _pais = value;
            }
        }


        private int _age;
        [Range(0, 99, Message = "Edad solo puede tener un valor entre 0 y 99")]
        public int Age {
            get {
                return _age;
            }
            set {
                _age = value;
            }
        }


        private string _bio;
        [Length(0, 150, Message = "Bio debe tener entre 0 y 150 caracteres.")]
        public string Bio {
            get {
                return _bio;
            }
            set {
                _bio = value;
            }
        }

        private string _site;
        [Pattern(Regex = @"(http|https)://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?", Message = "Formato incorrecto de URL")]
        public string Site {
            get {
                return _site;
            }
            set {
                _site = value;
            }
        }

        #endregion
    }
}